package com.hxd.otc.module.wallet.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.module.my.bean.WalletContactsBean;
import com.hxd.otc.module.wallet.adapter.WalletContactAdapter;
import com.hxd.otc.module.wallet.contract.WalletContactContract;
import com.hxd.otc.module.wallet.model.WalletModel;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;

/**
 * Created by lzy on 2018/8/6 0006.
 * description ${钱包联系人地址 Presenter}
 */
public class WalletContactPresenter extends BaseRecyclerPresenter<WalletContactContract.View, WalletContactAdapter, WalletContactsBean> implements WalletContactContract.Presenter {

    private final WalletModel mWalletModel;
    private String mFilterCoinType;
    String id;

    public void setId(String id) {
        this.id = id;
    }

    public WalletContactPresenter(WalletContactContract.View view) {
        super(view);
        mWalletModel = WalletModel.getInstance();
    }

    @Override
    public void setFilterCoinType(String filterCoinType) {
        mFilterCoinType = filterCoinType;
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mWalletModel.getContactByUserId(new BaseObserver<ArrayList<WalletContactsBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<WalletContactsBean> list) {
                onLoadDataSuccess(isRefresh, list);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<ArrayList<WalletContactsBean>>>bindAutoDispose(),id);
    }

    @Override
    public void deleteContacts(final int position, final WalletContactsBean walletContactsBean) {
        mWalletModel.deleteContactById(walletContactsBean.id, new BaseObserver<Object>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.deleteContactsSuccess(position, walletContactsBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean>bindAutoDispose());
    }

}
